import threading

lock = threading.Lock()
with lock:
    # 临界区: 等价于try: lock.acquire() xxx finally: lock.release()
    pass
